home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / dos / prg / pas / swag / crc.swg / 0013_File Checksum.pas < prev    next >
Pascal/Delphi Source File  |  1993-11-02  |  3KB  |  97 lines

  1. {
  2. Program/utility which can be used to check the 'sorted' File and the data
  3. File. It produces the Byte CheckSum of the Files (which must be identical),
  4. and can check the sortorder of the File (when given the option -s)...
  5. }
  6. {$A+,B-,D-,F-,G+,I-,L-,N-,O-,R-,S+,V-,X-}
  7. {$M 16384,0,655360}
  8. { Here is the Program CHECKSUM that you can run to check the master data
  9.   File For TeeCee's String sorting contest. if you have a slow machine I
  10.   suggest you set the Program running and go to bed!! :-)
  11.  
  12.   Code size: 5952 Bytes
  13.   Data size:  924 Bytes
  14.   .EXE size: 6304 Bytes
  15. }
  16. Uses
  17.   Crt;
  18.  
  19. Const
  20.   Version = 'CheckSum 1.0 (c) 1992 DwarFools & Consultancy, '+
  21.                                   'by drs. Robert E. Swart'#13#10;
  22.   Usage   = 'Usage: CheckSum dataFile [-s]'#13#10 +
  23.    '       Options: -s to check the sortorder of the Strings'#13#10;
  24.   MaxStr  = 30;
  25.   Error     : LongInt = 0;
  26.   Records   : LongInt = 0;
  27.   CheckSum  : Byte = 0;     { Byte CheckSum of all Bytes in data File xor'ed }
  28.   Sortorder : Boolean = False; { Assume option -s is not given }
  29.  
  30. Var
  31.   Str      : String[MaxStr];
  32.   len      : Byte Absolute Str;
  33.   ByteStr  : Array [0..MaxStr] of Byte Absolute Str;
  34.   PrevStr,
  35.   UpperStr : String[MaxStr];
  36.   f        : File;
  37.   i        : Integer;
  38.  
  39. begin
  40.   Writeln(Version);
  41.   if ParamCount = 0 then
  42.   begin
  43.     Writeln(Usage);
  44.     Halt;
  45.   end;
  46.  
  47.   assign(f, ParamStr(1)); { Change this to your chosen File name }
  48.   reset(f, 1);
  49.   if Ioresult <> 0 then
  50.   begin
  51.     Writeln('Error: could not open ', ParamStr(1));
  52.     Writeln(Usage);
  53.     Halt(1);
  54.   end;
  55.  
  56.   if (ParamCount = 2) and ((ParamStr(2) = '-s') or (ParamStr(2) = '-S')) then
  57.       Sortorder := True;
  58.  
  59.   Writeln('Strings x 1000 checked:');
  60.   While not eof(f) do
  61.   begin
  62.     BlockRead(f, len, 1);
  63.     BlockRead(f, Str[1], len);
  64.     For i := 0 to len do
  65.       CheckSum := CheckSum xor ByteStr[i];
  66.  
  67.     if Sortorder then
  68.     begin
  69.       UpperStr[0] := Str[0];
  70.       For i := 1 to len do
  71.         UpperStr[i] := UpCase(Str[i]);
  72.       if Records > 0 then
  73.       begin
  74.         if PrevStr > UpperStr then
  75.         begin
  76.           Inc(Error);
  77.           Writeln;
  78.           Writeln('Error: ',PrevStr,' > ',UpperStr);
  79.         end;
  80.         PrevStr := UpperStr;
  81.       end;
  82.     end;
  83.     Inc(Records);
  84.     if (Records mod 1000) = 0 then
  85.     begin
  86.       GotoXY(1, WhereY);
  87.       Write(Records div 1000:3);
  88.     end;
  89.   end;
  90.   close(f);
  91.   Writeln;
  92.   Write(Records,' Strings checked, ');
  93.   if Sortorder then
  94.     Writeln(Error, ' Errors found, ');
  95.   Writeln('Byte CheckSum = ', CheckSum);
  96. end.
  97.